<template>
  <div class="mod-config editViewContainer">
    <split-pane class="splitPane" :min-percent='10' :default-percent='10' split="vertical">
      <template slot="paneL">
        <div class="treeViewContainer">
          <tree-view ref="treeView" :treeData="productDeviceTreeList" :checkChangedHandler="getDataList"></tree-view>
        </div>
      </template>
      <template slot="paneR">
        <table-view ref="view"
                    :searchAttrs="searchAttrs"
                    :primaryKey="primaryKey"
                    :listApiName="listApiName"
                    :deleteApiName="deleteApiName"
                    :showAttrs="showAttrs"
                    :exportAuthName="exportAuthName"
                    :optionWidth="100"
                    :exportPlantFunc="exportPlantFunc"
        >
          <template v-slot:header>
            <el-button v-if="isAuth(boxOrderAuthName)" size="small" type="danger" @click="exportOrderNotFinish">
              导出未完成所有订单
            </el-button>
          </template>
          <template v-slot:foot="{scope}">
            <el-tooltip v-if="isAuth(sendOrderLeadApprovalAuthName)" class="item" effect="dark" content="修改订单状态"
                        placement="bottom" :hide-after="1800" :open-delay="800">
              <el-button type="primary" icon="el-icon-brush" size="small"
                         @click="openOrderStatusDialog(R.prop('row', scope))"></el-button>
            </el-tooltip>
<!--            <el-tooltip v-if="isAuth(boxOrderAuthName)" class="item" effect="dark" content="修改纸箱订购状态"
                        placement="bottom" :hide-after="1800" :open-delay="800">
              <el-button type="text" size="small" @click="openBoxOrderStatusDialog(R.prop('row', scope))">纸箱订购
              </el-button>
            </el-tooltip>
            <el-tooltip v-if="isAuth(sendOrderLeadApprovalAuthName)" class="item" effect="dark" content="修改订单产线"
                        placement="bottom" :hide-after="1800" :open-delay="800">
              <el-button type="text" size="small" @click="openProductDeviceDialog(R.prop('row', scope))">产线
              </el-button>
            </el-tooltip>
            <el-tooltip class="item" effect="dark" content="添加损耗数" placement="bottom" :hide-after="1800"
                        :open-delay="800">
              <el-button size="small" type="text" @click="openOrderIssuesNumberDialog(R.prop('row', scope))">
                损耗数
              </el-button>
            </el-tooltip>

            <el-tooltip v-if="isAuth(boxOrderAuthName)" class="item" effect="dark" content="修改标记膏霜大口"
                        placement="bottom" :hide-after="1800" :open-delay="800">
              <el-button size="small" type="text" @click="openBigMouthDialog(R.prop('row', scope))">
                标记大口
              </el-button>
            </el-tooltip>
            <el-tooltip v-if="isAuth(sendOrderLeadApprovalAuthName)" class="item" effect="dark" content="排单审核"
                        placement="bottom" :hide-after="1800" :open-delay="800">
              <el-button size="small" type="text" @click="openSendOrderDialog(R.prop('row', scope))">
                排单审核
              </el-button>
            </el-tooltip>
            <el-tooltip v-if="isAuth(boxOrderAuthName)" class="item" effect="dark" content="纸箱审核" placement="bottom"
                        :hide-after="1800" :open-delay="800">
              <el-button size="small" type="text" @click="openBoxAuditStatusDialog(R.prop('row', scope))">
                纸箱审核
              </el-button>
            </el-tooltip>

            <el-tooltip v-if="isAuth(modelAuthName)" class="item" effect="dark" content="模具审核" placement="bottom"
                        :hide-after="1800" :open-delay="800">
              <el-button size="small" type="text" @click="openModelApprovalDialog(R.prop('row', scope))">
                模具审核
              </el-button>
            </el-tooltip>-->
          </template>
        </table-view>
      </template>
    </split-pane>

    <add-or-update v-if="addOrUpdateVisible" ref="addOrUpdate" @refreshDataList="getDataList"></add-or-update>
    <productinfo-add-or-update v-if="productInfoVisible" ref="productInfo"></productinfo-add-or-update>
    <client-info-add-or-update v-if="clientInfoVisible" ref="clientInfo"></client-info-add-or-update>
    <productplannotice-add-or-update v-if="productPlanNoticeVisible" ref="productPlanNotice"
                                     @refreshDataList="getDataList"></productplannotice-add-or-update>
    <deep-category-add-or-update v-if="deepCategoryInfoVisible" ref="deepCategory"></deep-category-add-or-update>
    <model-info-add-or-update v-if="modelInfoVisible" ref="modelInfo"></model-info-add-or-update>
    <order-model-add-or-update v-if="orderModelVisible" ref="orderModelInfo"></order-model-add-or-update>

    <commodity-info-add-or-update-order v-if="commodityInfoVisible" ref="commodityInfo"></commodity-info-add-or-update-order>


    <bottle-cap-info-add-or-update v-if="bottleCapInfoVisible" ref="relateBottleCapInfo"></bottle-cap-info-add-or-update>
    <center-cover-info-add-or-update v-if="centerCoverInfoVisible" ref="relateCenterCoverInfo"></center-cover-info-add-or-update>
    <neck-ring-info-add-or-update v-if="neckRingInfoVisible" ref="relateNeckRingInfo"></neck-ring-info-add-or-update>
    <spray-head-info-add-or-update v-if="sprayHeadInfoVisible" ref="relateSprayHeadInfo"></spray-head-info-add-or-update>


    <el-dialog
      title="选择当前订单的状态"
      :visible.sync="dialogVisible"
      width="30%">
      <el-radio-group v-model="status" size="small">
        <el-radio border :label="-1" style="margin-left: 13px; margin-bottom: 5px">预排</el-radio>
        <el-radio border :label="0" style="margin-bottom: 5px">待配货</el-radio>
        <el-radio border :label="1" style="margin-bottom: 5px">暂时下线</el-radio>
        <el-radio border :label="2" style="margin-bottom: 5px">加急</el-radio>
        <el-radio border :label="3" style="margin-bottom: 5px">正常</el-radio>
        <el-radio border :label="4">生产中</el-radio>
        <el-radio border :label="5">生产完成</el-radio>
        <el-radio border :label="90" style="margin-bottom: 5px">客户待确认</el-radio>
        <el-radio border :label="99">取消</el-radio>
      </el-radio-group>
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="modifyOrderStatus">确 定</el-button>
      </span>
    </el-dialog>

    <el-dialog
      title="选择当前纸箱下单的状态"
      :visible.sync="boxOrderDialogVisible"
      width="30%">

      <div style="margin-left: 20px;margin-bottom: 20px;">
        <span>纸箱厂：   </span>
        <el-select v-model="boxFactoryId" style="display: inline-block" filterable clearable
                   placeholder="请选择下单纸箱厂">
          <el-option
            v-for="item in boxFactoryList"
            :key="item.id"
            :label="item.name"
            :value="item.id">
          </el-option>
        </el-select>
      </div>

      <div style="margin-left: 20px">
        <span>纸箱下单状态：   </span>
        <el-radio-group v-model="boxOrderStatusRadio">
          <el-radio :label="0">未下单</el-radio>

          <el-radio :label="2">已下单</el-radio>

          <el-radio :label="5">正在加工</el-radio>

          <el-radio :label="7">加工完成</el-radio>

          <el-radio :label="10">入库完成</el-radio>

          <el-radio :label="15">改用托盘</el-radio>

          <el-radio :label="20">自供</el-radio>
        </el-radio-group>
      </div>


      <span slot="footer" class="dialog-footer">
        <el-button @click="boxOrderDialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="modifyBoxOrderStatus">确 定</el-button>
      </span>
    </el-dialog>

    <el-dialog
      title="排单审核状态"
      :visible.sync="sendOrderLeadApprovalDialogVisible"
      width="30%">
      <label>审批状态： </label>
      <el-radio-group v-model="sendOrderLeadApproval">
        <el-radio :label="9" border>排单待审核</el-radio>

        <el-radio :label="10" border>排单驳回</el-radio>

        <el-radio :label="11" border>排单通过</el-radio>

      </el-radio-group>
      <br>
      <br>
      <label>审批意见： </label>
      <el-input v-model="sendOrderOpinion" placeholder="请输入排单审核意见">
      </el-input>
      <span slot="footer" class="dialog-footer">
        <el-button @click="sendOrderLeadApprovalDialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="modifySendOrderApproval">确 定</el-button>
      </span>
    </el-dialog>
    <el-dialog
      title="纸箱审核状态"
      :visible.sync="boxAuditDialogVisible"
      width="30%">
      <el-radio-group v-model="boxAuditStatusRadio">
        <el-radio :label="0">未审核</el-radio>

        <el-radio :label="1">已审核</el-radio>

        <el-radio :label="2">驳回，修改</el-radio>

      </el-radio-group>
      <span slot="footer" class="dialog-footer">
        <el-button @click="boxAuditDialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="modifyBoxAuditStatus">确 定</el-button>
      </span>
    </el-dialog>

    <el-dialog
      title="模具审核状态"
      :visible.sync="modelApprovalDialogVisible"
      width="30%">
      <div style="margin-top: 20px">
        <label>模具编号： </label>
        <el-select v-model="modelId" filterable clearable placeholder="请选择模具">
          <el-option
            v-for="item in modelInfoList"
            :key="item.id"
            :label="item.name"
            :value="item.id">
          </el-option>
        </el-select>
      </div>

      <div style="margin-top: 20px">
        <label>模具位置： </label>
        <el-select v-model="modelShelfId" filterable clearable placeholder="请选择新的模具位置">
          <el-option
            v-for="item in modelShelfList"
            :key="item.id"
            :label="item.name"
            :value="item.id">
          </el-option>
        </el-select>
      </div>


      <div style="margin-top: 20px">
        <label>可上机模具组数： </label>
        <el-input-number style="margin-top: 20px" v-model="groupNumber" placeholder="可上机模具组数"></el-input-number>
      </div>

      <div style="margin-top: 15px">
        <label>审核状态： </label>
        <el-radio-group v-model="modelApprovalRadio">
          <el-radio border :label="0">未审核</el-radio>

          <el-radio border :label="1">已审核</el-radio>

          <el-radio border :label="2">模具未到位</el-radio>
        </el-radio-group>
      </div>

      <div style="margin-top: 20px">
        <label>审批意见： </label>
        <el-input style="margin-top: 20px" v-model="modelOpinion" placeholder="请输入模具审核意见"></el-input>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button @click="modelApprovalDialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="modifyModelApprovalStatus">确 定</el-button>
      </span>
    </el-dialog>

    <el-dialog
      title="修改损耗数量"
      :visible.sync="orderIssuesNumberVisible"
      width="30%">
      <el-input-number v-model="orderIssuesNumber">
      </el-input-number>
      <span slot="footer" class="dialog-footer">
        <el-button @click="orderIssuesNumberVisible = false">取 消</el-button>
        <el-button type="primary" @click="modifyOrderIssuesNumber">确 定</el-button>
      </span>
    </el-dialog>

    <el-dialog
      title="修改标记膏霜大口"
      :visible.sync="bigMouthVisible"
      width="30%">
      <el-input v-model="bigMouth" placeholder="请输入标记膏霜大口">
      </el-input>
      <span slot="footer" class="dialog-footer">
        <el-button @click="bigMouthVisible = false">取 消</el-button>
        <el-button type="primary" @click="modifyBigMouth">确 定</el-button>
      </span>

    </el-dialog>

    <el-dialog
      title="修改订单产线"
      :visible.sync="productDeviceDialogVisible"
      width="30%">

      <div style="margin-bottom: 20px">
        <el-tag> 产线:</el-tag>

        <el-select v-model="productDeviceRadio" @change="changeProductDeviceId(productDeviceRadio)" clearable filterable
                   placeholder="请选择">
          <el-option
            v-for="item in productDeviceList"
            :key="item.id"
            :label="item.name"
            :value="item.id">
          </el-option>
        </el-select>
      </div>

      <el-tag> 机台：</el-tag>

      <el-select v-model="deviceWorkbenchList" multiple clearable filterable placeholder="机台">
        <el-option
          v-for="item in productDeviceWorkbenchList"
          :key="item.id"
          :label="item.name"
          :value="item.id">
        </el-option>
      </el-select>

      <span slot="footer" class="dialog-footer">
        <el-button @click="productDeviceDialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="modifyProductDeviceStatus">确 定</el-button>
      </span>
    </el-dialog>

    <el-dialog
      title="批量制定生产计划"
      :visible.sync="orderPlanNoticeVisible"
      width="90%">

      <el-form
        ref="dataForm"
        label-width="120px"
        label-position="left"
        style="margin-left:30px"
      >

        <el-form-item label="生产线" style="width: 400px">
          <el-select v-model="deviceId" clearable filterable @change="changeProductDeviceId(deviceId)"
                     placeholder="请选择">
            <el-option
              v-for="item in productDeviceList"
              :key="item.id"
              :label="item.name"
              :value="item.id">
            </el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="上机时间" style="width: 400px">
          <el-date-picker
            v-model="onlineTime"
            align="right"
            type="date"
            placeholder="选择日期"
            value-format="yyyy-MM-dd HH:mm:ss"
          >
          </el-date-picker>
        </el-form-item>


      </el-form>

      <el-table
        :data="tableListData"
        border
        style="display: inline-block">
        <el-table-column
          prop="id"
          label="订单编号"
          align="center"
          width="150"
        >
          <template slot-scope="scope">
            <el-select v-model="scope.row.id" disabled placeholder="请选择">
              <el-option
                v-for="item in orderDetailList"
                :key="item.id"
                :label="item.name"
                :value="item.id">
              </el-option>
            </el-select>
          </template>
        </el-table-column>

        <el-table-column
          prop="modelId"
          label="模具名称"
          align="center"
          width="150"
        >
          <template slot-scope="scope">
            <el-select v-model="scope.row.modelId" clearable filterable placeholder="请选择">
              <el-option
                v-for="item in modelInfoList"
                :key="item.id"
                :label="item.name"
                :value="item.id">
              </el-option>
            </el-select>
          </template>
        </el-table-column>

        <el-table-column
          prop="productId"
          label="产品名称"
          align="center"
          width="150"
        >
          <template slot-scope="scope">
            <el-select v-model="scope.row.productId" disabled placeholder="请选择">
              <el-option
                v-for="item in productInfoList"
                :key="item.id"
                :label="item.name"
                :value="item.id">
              </el-option>
            </el-select>
          </template>
        </el-table-column>

        <el-table-column
          prop="productWeight"
          label="克重"
          width="130"
          align="center"
        >
          <template slot-scope="scope">
            <el-input-number controls-position="right" size="small" :min="0" v-model="scope.row.productWeight"
                             placeholder="克重"></el-input-number>
          </template>
        </el-table-column>
        <el-table-column
          prop="weightScope"
          label="克重范围"
          width="110"
          align="center"
        >
          <template slot-scope="scope">
            <el-input controls-position="right" size="small" v-model="scope.row.weightScope"
                      placeholder="克重误差范围"></el-input>
          </template>
        </el-table-column>
        <el-table-column
          prop="duration"
          label="机台"
          align="center"
          width="210"
        >
          <template slot-scope="scope">
            <el-select v-model="scope.row.deviceWorkbenchList" multiple clearable filterable placeholder="机台">
              <el-option
                v-for="item in productDeviceWorkbenchList"
                :key="item.id"
                :label="item.name"
                :value="item.id">
              </el-option>
            </el-select>
          </template>
        </el-table-column>
        <el-table-column
          prop="productVolume"
          label="标准容量"
          width="110"
          align="center"
        >
          <template slot-scope="scope">
            <el-input-number controls-position="right" size="small" v-model="scope.row.productVolume"
                             placeholder="标准容量"></el-input-number>
          </template>
        </el-table-column>

        <el-table-column
          prop="volumeScope"
          label="容量范围"
          width="110"
          align="center"
        >
          <template slot-scope="scope">
            <el-input controls-position="right" size="small" v-model="scope.row.volumeScope"
                      placeholder="容量范围"></el-input>
          </template>
        </el-table-column>

        <el-table-column
          prop="specialMark"
          label="箱唛"
          align="center"
          width="110"
        >
          <template slot-scope="scope">
            <el-select v-model="scope.row.specialMark" clearable filterable placeholder="箱唛">
              <el-option label="普英唛" :value=0>普英唛</el-option>
              <el-option label="专用唛" :value=1>专用唛</el-option>
              <el-option label="普英唛+H" :value=2>普英唛+H</el-option>
            </el-select>
          </template>
        </el-table-column>

        <el-table-column
          prop="orderProductNumber"
          label="数量(含损耗)"
          width="150"
          align="center"
        >
          <template slot-scope="scope">
            <el-input-number controls-position="right" size="small" :min="0"
                             v-model="scope.row.orderProductNumber+scope.row.orderIssuesNumber"
                             placeholder="数量(含损耗)"></el-input-number>
          </template>
        </el-table-column>

        <el-table-column
          prop="groupNumber"
          label="模具组数"
          width="100"
          align="center"
        >
          <template slot-scope="scope">
            <el-input-number controls-position="right" size="small" :min="0" v-model="scope.row.groupNumber"
                             placeholder="模具组数"></el-input-number>
          </template>
        </el-table-column>

        <el-table-column
          prop="bottleOutDiameter"
          label="口径"
          align="center"
        >
          <template slot-scope="scope">
            <el-input size="small" v-model="scope.row.bottleOutDiameter" placeholder="口径"></el-input>
          </template>
        </el-table-column>


<!--        <el-table-column-->
<!--          prop="deepCategoryList"-->
<!--          label="深加工方式"-->
<!--          width="100"-->
<!--          align="center"-->
<!--        >-->
<!--          <template slot-scope="scope">-->
<!--            <el-select v-model="scope.row.deepCategoryIdList" multiple clearable filterable placeholder="请选择">-->
<!--              <el-option-->
<!--                v-for="item in deepCategoryList"-->
<!--                :key="item.id"-->
<!--                :label="item.name"-->
<!--                :value="item.id">-->
<!--              </el-option>-->
<!--            </el-select>-->
<!--          </template>-->
<!--        </el-table-column>-->

        <el-table-column
          prop="remark"
          label="备注"
          width="150"
          align="center"
        >
          <template slot-scope="scope">
            <el-input type="textarea" controls-position="right" size="small" :min="0" v-model="scope.row.remark"
                      placeholder="备注"></el-input>
          </template>
        </el-table-column>
      </el-table>


      <span slot="footer" class="dialog-footer">
        <el-button @click="orderPlanNoticeVisible = false">取 消</el-button>
        <el-button type="primary" @click="updatePlanOrderStatus">确 定</el-button>
      </span>

    </el-dialog>

  </div>
</template>

<script>
import AddOrUpdate from './orderdetail-add-or-update'
import tableView from '@/components/tableView'
import basicMixins from '@/utils/commonViewMixins'
import ProductinfoAddOrUpdate from '@/views/modules/product/productinfo-add-or-update'
import ProductplannoticeAddOrUpdate from '@/views/modules/product/productplannotice-add-or-update'
import OrderModelAddOrUpdate from './ordermodel-add-or-update'
import ClientInfoAddOrUpdate from '@/views/modules/client/clientinfo-add-or-update'
import DeepCategoryAddOrUpdate from '@/views/modules/deep/deepcategory-add-or-update'
import CommodityInfoAddOrUpdateOrder from '@/views/modules/commodity/commodityinfo-add-or-update-order'
import BottleCapInfoAddOrUpdate from '@/views/modules/relate/relatebottlecapinfo-add-or-update'
import CenterCoverInfoAddOrUpdate from '@/views/modules/relate/relatecentercoverinfo-add-or-update'
import NeckRingInfoAddOrUpdate from '@/views/modules/relate/relateneckringinfo-add-or-update'
import SprayHeadInfoAddOrUpdate from '@/views/modules/relate/relatesprayheadinfo-add-or-update'

import {mRequest} from '@/utils/request'
import {exportHandle, isAuth} from '@/utils'
import ModelInfoAddOrUpdate from '@/views/modules/model/modelinfo-add-or-update'
import treeView from '@/components/treeView'
import relatesprayheadinfoAddOrUpdate from '@/views/modules/relate/relatesprayheadinfo-add-or-update.vue'

export default {
  mixins: [basicMixins],
  data() {
    return {
      isAuth: isAuth,
      status: 0,
      bigMouth: '',
      boxOrderStatusRadio: 0,
      boxAuditStatusRadio: 0,
      productDeviceRadio: 0,
      productDeviceWorkbenchList: [],
      deviceWorkbenchList: [],
      orderIssuesNumber: 0,
      modelApprovalRadio: 0,
      groupNumber: 0,
      modelId: '',
      orderDetailId: '',
      boxFactoryId: '',
      modelShelfId: '',
      dialogVisible: false,
      modelInfoVisible: false,
      orderIssuesNumberVisible: false,
      boxOrderDialogVisible: false,
      productPlanNoticeVisible: false,
      productInfoVisible: false,
      clientInfoVisible: false,
      deepCategoryInfoVisible: false,
      bigMouthVisible: false,
      orderPlanNoticeVisible: false,
      boxAuditDialogVisible: false,
      productDeviceDialogVisible: false,
      sendOrderLeadApprovalDialogVisible: false,
      modelApprovalDialogVisible: false,
      orderModelVisible: false,
      commodityInfoVisible: false,
      bottleCapInfoVisible: false,
      centerCoverInfoVisible: false,
      neckRingInfoVisible: false,
      sprayHeadInfoVisible: false,
      productDeviceList: [],
      deviceIdList: [],
      boxFactoryList: [],
      orderDetailList: [],
      productInfoList: [],
      modelInfoList: [],
      tableListData: [],
      deepCategoryList: [],
      productDeviceTreeList: [],
      modelShelfList: [],
      sendOrderLeadApproval: 11,
      sendOrderOpinion: '',
      durationList: [],
      modelOpinion: '',
      defaultProps: {
        children: 'children',
        label: 'name'
      },
      sysUserList: [],
      deviceId: '',
      onlineTime: '',
      searchAttrs: {
        productNo: {
          label: '产品名称',
          placeholder: '请输入产品名称'
        },
        productWeight: {
          label: '产品重量',
          placeholder: '请输入重量'
        },
        status: {
          label: '订单状态',
          placeholder: '审核',
          type: 'list',
          list: [
            {id: -1, name: '预排产'},
            {id: 0, name: '待配货'},
            {id: 1, name: '暂时下线'},
            {id: 2, name: '加急'},
            {id: 3, name: '正常'},
            {id: 4, name: '生产中'},
            {id: 10, name: '出库中'},
            {id: 11, name: '出库完成'},
            {id: 50, name: '出库中'},
            {id: 55, name: '出库完成'},
            {id: 30, name: '计划上线中'},
            {id: 32, name: '计划加急'}
          ]
        },
        createUser: {
          label: '销售',
          clearable: true,
          type: 'autoComplete',
          placeholder: '请选择销售人员',
          querySearchApiName: 'systemApi/listSaleUser'
        },
        sendOrderLeadApproval: {
          label: '排单审核',
          placeholder: '排单审核',
          type: 'list',
          list: [
            {id: 9, name: '待审核'},
            {id: 10, name: '驳回'},
            {id: 11, name: '已审核'}
          ]
        },
        deviceId: {
          type: 'func',
          dataFunc: () => {
            return this.$refs.treeView.$refs.treeForm.getCheckedKeys()[0]
          }
        },
        clientId: {
          label: '客户名称',
          clearable: true,
          type: 'autoComplete',
          placeholder: '请输入客户名称',
          querySearchApiName: 'clientApi/getClientList'
        },
        specialMark: {
          label: '箱唛',
          clearable: true,
          placeholder: '请选择箱唛',
          type: 'list',
          list: []
        },
        // manufacturerType:{
        //   label: '深加工在厂',
        //   clearable: true,
        //   placeholder: '深加工在厂',
        //   type: 'list',
        //   list: [],
        // },
        boxAudit: {
          label: '纸箱审核',
          clearable: true,
          placeholder: '请选择纸箱审核状态',
          type: 'list',
          list: []
        },
        dateTimeRange: {
          type: 'date',
          dateType: 'daterange',
          clearable: true
        }
      },
      primaryKey: 'id',
      listApiName: 'orderApi/listOrderDetail',
      deleteApiName: 'orderApi/deleteOrderDetail',
      importApiName: 'orderApi/importOrderDetail',
      saveAuthName: 'order:orderdetail:save',
      deleteAuthName: 'order:orderdetail:delete',
      boxOrderAuthName: 'order:orderdetail:boxOrder',
      modelAuthName: 'order:orderdetail:modelAuth',
      exportAuthName: 'order:orderdetail:exportOrderPlan',
      sendOrderLeadApprovalAuthName: 'order:orderdetail:sendOrderLeadApproval',

      showAttrs: {

        orderNo: {
          label: '订单编号',
          width: 150,
          type: 'labelWithStatus',
          statusAttr: 'messageStatus',
          items: [
            {value: 0, text: '未读', tagType: 'danger'}
          ]
        },
        orderTime: {label: '订单时间', type: 'date', width: 100},


        // modelNo: {
        //   label: '模具编号',
        //   width: 140,
        //   type: 'linkLabel',
        //   routerName: 'model-modelinfo',
        //   searchKey: 'modelNo'
        // },
        productWeightStr: {label: '订单克数'},
        status: {
          label: '状态',
          type: 'radio',
          width: 65,
          items: [
            {value: -1, text: '预排产', tagType: 'danger'},
            {value: 0, text: '待配货', tagType: 'info'},
            {value: 1, text: '暂时下线', tagType: 'warning'},
            {value: 2, text: '加急', tagType: 'warning'},
            {value: 3, text: '正常', tagType: 'primary'},
            {value: 4, text: '生产中', tagType: 'primary'},
            {value: 5, text: '生产完成', tagType: 'success'},
            {value: 10, text: '出库中', tagType: 'warning'},
            {value: 11, text: '出库完成', tagType: 'success'},
            {value: 30, text: '计划上线中', tagType: 'success'},
            {value: 32, text: '计划加急', tagType: 'danger'},
            {value: 90, text: '待确认', tagType: 'info'},
            {value: 99, text: '取消', tagType: 'danger'}
          ]
        },
        // approvalStatus: {
        //   label: '审核',
        //   type: 'radio',
        //   width: 75,
        //   items: [
        //     {value: null, text: '未审核', tagType: 'info'},
        //     {value: 0, text: '未审核', tagType: 'info'},
        //     {value: 3, text: '组长待审核', tagType: 'warning'},
        //     {value: 4, text: '组长驳回', tagType: 'danger'},
        //     {value: 5, text: '组长通过', tagType: 'success'},
        //     {value: 9, text: '排单待审核', tagType: 'warning'},
        //     {value: 10, text: '排单驳回', tagType: 'danger'},
        //     {value: 11, text: '排单通过', tagType: 'primary'},
        //     {value: 15, text: '纸箱待审核', tagType: 'info'},
        //     {value: 16, text: '纸箱驳回', tagType: 'danger'},
        //     {value: 17, text: '纸箱通过', tagType: 'success'},
        //     {value: 18, text: '模具未审核', tagType: 'info'},
        //     {value: 19, text: '模具通过', tagType: 'success'},
        //     {value: 20, text: '模具未到位', tagType: 'danger'},
        //     {value: 30, text: '纸箱未下单', tagType: 'warning'},
        //     {value: 33, text: '纸箱已下单', tagType: 'success'},
        //     {value: 35, text: '纸箱已到位', tagType: 'success'},
        //     {value: 66, text: '全部通过', tagType: 'success'}
        //   ]
        // },
        deliveryTime: {label: '交货时间', type: 'date', width: 95},
        orderProductNumberStr: {label: '订单数量', width: 95},

        /*  unitPrice: {
            //   label: '含深加工价格',
            //   showAuthName: 'order:unitprice:show'
             },*/

        productNo: {
          label: '产品编号',
          width: 140,
          type: 'linkLabel',
          routerName: 'product-product-info-all',
          searchKey: 'productNo'
        },
        productVolumeStr: {label: '订单容量'},
        remark: {label: '备注', width: 140},

        unitPrice: {
          label: '价格',
          showAuthName: 'order:unitprice:show'
        },
        clientName: {label: '客户', width: 150, showAuthName: 'order:unitprice:show'},
        // deepProductImage: {label: '深加工样图', type: 'image'},
        salesperson: {label: '销售'},
        bottleCraft: {label: '工艺'},
        bottleOutDiameter: {label: '瓶口外径'},

      }
    }
  },

  mounted() {
    this.productDeviceTreeListInit()
  },
  methods: {

    productDeviceTreeListInit() {
      mRequest('productApi/getProductDeviceListByParent', {}, (res) => {
        this.productDeviceList = this.R.pathOr([], ['data', 'list'], res)
        const productDeviceTreeList = [{
          id: '',
          name: '生产线信息',
          nodeType: 0,
          children: []
        }]

        productDeviceTreeList[0].children = this.productDeviceList
        this.productDeviceTreeList = productDeviceTreeList
      })
      this.searchAttrs['boxAudit'].list = [
        {
          id: 0, name: '未审核'
        },
        {
          id: 1, name: '已审核'
        }
      ]
      this.searchAttrs['specialMark'].list = [
        {
          id: 0, name: '普英唛'
        },
        {
          id: 1, name: '专用唛'
        },
        {
          id: 2, name: '普英唛+H'
        }
      ]

      this.searchAttrs['status'].list = [
        {id: -1, name: '缺货'},
        {id: 0, name: '待配货'},
        {id: 15, name: '采购中'},
        {id: 17, name: '采购完成'},
        {id: 20, name: '未出货'},
        {id: 50,name: '部分发货'},
        {id: 55,name: '已全出货' },
        {id: 66, name: '已签收'},
        {id: 90, name: '客户退货'},
        {id: 99, name: '订单取消'}
      ],

        mRequest('boxApi/getBoxFactoryList', {}, (res) => {
          this.boxFactoryList = this.R.pathOr([], ['data', 'list'], res)
        })
    },
    openOrderStatusDialog(order) {
      this.dialogVisible = true
      this.modifyOrder = order
      const {status} = order

      this.status = status
    },
    modifyOrderStatus() {
      if (this.modifyOrder.status === this.status) {
        return
      }
      this.modifyOrder.status = this.status

      mRequest('orderApi/updateOrderDetail', this.modifyOrder, () => {
        this.modifyOrder = null
        this.status = 0
        this.dialogVisible = false
        this.getDataList()
      })
    },
    modifyBigMouth() {
      if (this.modifyOrder.bigMouth === this.bigMouth) {
        return
      }
      this.modifyOrder.bigMouth = this.bigMouth

      mRequest('orderApi/updateOrderDetail', this.modifyOrder, () => {
        this.modifyOrder = null
        this.bigMouth = ''
        this.bigMouthVisible = false
        this.getDataList()
      })
    },
    openBigMouthDialog(order) {
      this.bigMouthVisible = true
      this.modifyOrder = order
      const {bigMouth} = order

      this.bigMouth = bigMouth
    },

    openBoxOrderStatusDialog(order) {
      this.boxOrderDialogVisible = true
      this.modifyOrder = order
      const {boxOrderStatus} = order
      const {boxFactoryId} = order

      this.boxOrderStatusRadio = boxOrderStatus
      this.boxFactoryId = boxFactoryId
    },
    modifyBoxOrderStatus() {
      /*    if (this.modifyOrder.boxOrderStatus === this.boxOrderStatusRadio) {
            return
          }*/
      this.modifyOrder.boxOrderStatus = this.boxOrderStatusRadio
      this.modifyOrder.boxFactoryId = this.boxFactoryId
      mRequest('orderApi/updateOrderDetail', this.modifyOrder, () => {
        this.modifyOrder = null
        this.boxOrderStatusRadio = 0
        this.boxOrderDialogVisible = false
        this.getDataList()
      })
    },
    //纸箱审核
    openBoxAuditStatusDialog(order) {
      this.boxAuditDialogVisible = true

      this.modifyOrder = order
      const {boxAudit} = order

      this.boxAuditStatusRadio = boxAudit
    },
    modifyBoxAuditStatus() {
      if (this.R.equals(this.modifyOrder.boxAudit, this.boxAuditStatusRadio)) {
        this.modifyOrder = null
        this.boxAuditStatusRadio = 0
        this.boxAuditDialogVisible = false
        return
      }
      this.modifyOrder.boxAudit = this.boxAuditStatusRadio

      mRequest('orderApi/updateOrderDetail', this.modifyOrder, () => {
        this.modifyOrder = null
        this.boxAuditStatusRadio = 0
        this.boxAuditDialogVisible = false
        this.getDataList()
      })
    },
    //派单审核
    openSendOrderDialog(order) {
      this.sendOrderOpinion = null
      this.sendOrderLeadApprovalDialogVisible = true

      this.modifyOrder = order
      const {sendOrderLeadApproval} = order

      this.sendOrderLeadApproval = sendOrderLeadApproval
      this.sendOrderOpinion = order.sendOrderOpinion
    },
    modifySendOrderApproval() {
      if (this.modifyOrder.sendOrderLeadApproval === this.sendOrderLeadApproval) {
        return
      }
      this.modifyOrder.sendOrderLeadApproval = this.sendOrderLeadApproval
      this.modifyOrder.sendOrderOpinion = this.sendOrderOpinion

      mRequest('orderApi/updateOrderDetail', this.modifyOrder, () => {
        this.modifyOrder = null
        this.sendOrderLeadApproval = 0
        this.sendOrderOpinion = null
        this.sendOrderLeadApprovalDialogVisible = false
        this.getDataList()
      })
    },
    modifyOrderIssuesNumber() {
      if (this.modifyOrder.orderIssuesNumber === this.orderIssuesNumber) {
        return
      }
      this.modifyOrder.orderIssuesNumber = this.orderIssuesNumber

      mRequest('orderApi/updateOrderDetail', this.modifyOrder, () => {
        this.modifyOrder = null
        this.orderIssuesNumber = 0
        this.orderIssuesNumberVisible = false
        this.getDataList()
      })
    },
    //模具审核
    openModelApprovalDialog(order) {

      this.initModelInfoList()
      this.initModelShelfList()
      this.modelApprovalDialogVisible = true

      this.modifyOrder = order
      const {modelApproval, modelOpinion, modelId, modelShelfId, groupNumber,id} = order

      this.modelApprovalRadio = modelApproval
      this.modelOpinion = modelOpinion
      this.modelId = modelId
      this.modelShelfId = modelShelfId
      this.groupNumber = groupNumber
    },
    modifyModelApprovalStatus() {

      mRequest('modelApi/updateModelInfoByOrderInfo', {
        'id': this.modelId,
        'productId': this.modifyOrder.productId,
        'shelfId': this.modelShelfId
      }, () => {
      //  this.modelId = ''
      //  this.modelShelfId = ''

      })
      // if (this.R.equals(this.modifyOrder.modelApproval, this.modelApprovalRadio)) {
      //   this.modifyOrder = null
      //   this.modelOpinion = null
      //   this.modelApprovalRadio = 0
      //   this.modelShelfId = ''
      //   this.modelApprovalDialogVisible = false
      //   return
      // }
      this.modifyOrder.modelApproval = this.modelApprovalRadio
      this.modifyOrder.modelOpinion = this.modelOpinion
      this.modifyOrder.groupNumber = this.groupNumber
      this.modifyOrder.modelId = this.modelId

      mRequest('orderApi/updateOrderDetail', this.modifyOrder, () => {
        this.modifyOrder = null
        this.modelOpinion = null
        this.modelApprovalRadio = 0
        this.modelApprovalDialogVisible = false
        this.getDataList()
      })
    },
    openProductPlanNotice(id) {
      this.productPlanNoticeVisible = true
      this.$nextTick(() => {
        if (!this.R.isNil(this.$refs.productPlanNotice)) {
          this.$refs.productPlanNotice.init(null, {orderDetailId: id}, () => {
            this.$router.push({name: 'product-productplannotice'})
          })
        }
      })
    },
    openProductDeviceDialog(order) {
      this.productDeviceDialogVisible = true

      this.modifyOrder = order
      const {deviceId} = order
      const {deviceWorkbenchList} = order

      this.productDeviceRadio = deviceId
      if (deviceWorkbenchList) {
        this.deviceWorkbenchList = deviceWorkbenchList
      }

      this.initProduceDeviceWorkbenchList(deviceId)

    },
    modifyProductDeviceStatus() {
      /*    if (this.modifyOrder.deviceId === this.productDeviceRadio) {
            return
          }*/
      this.modifyOrder.deviceId = this.productDeviceRadio
      this.modifyOrder.deviceWorkbenchList = this.deviceWorkbenchList

      mRequest('orderApi/updateOrderDetail', this.modifyOrder, () => {
        this.modifyOrder = null
        this.productDeviceRadio = 0
        this.deviceWorkbenchList = []
        this.productDeviceDialogVisible = false
        this.getDataList()
      })
    },
    openProductInfoDialog(clientId, cb) {
      this.productInfoVisible = true
      this.$nextTick(() => {
        if (!this.R.isNil(this.$refs.productInfo)) {
          this.$refs.productInfo.init(null, {'clientId': clientId, status: 1}, cb)
        }
      })
    },
    openCommodityInfoDialog(cb) {
      this.commodityInfoVisible = true
      this.$nextTick(() => {
        if (!this.R.isNil(this.$refs.commodityInfo)) {
          this.$refs.commodityInfo.init(null, {status: 1}, cb)
        }
      })
    },

    openBottleCapInfoDialog(cb) {
      this.bottleCapInfoVisible = true
      this.$nextTick(() => {
        if (!this.R.isNil(this.$refs.relateBottleCapInfo)) {
          this.$refs.relateBottleCapInfo.init(null, {status: 1}, cb)
        }
      })
    },
    openCenterCoverInfoDialog(cb) {
      this.centerCoverInfoVisible = true
      this.$nextTick(() => {
        if (!this.R.isNil(this.$refs.relateCenterCoverInfo)) {
          this.$refs.relateCenterCoverInfo.init(null, {status: 1}, cb)
        }
      })
    },
    openNeckRingInfoDialog(cb) {
      this.neckRingInfoVisible = true
      this.$nextTick(() => {
        if (!this.R.isNil(this.$refs.relateNeckRingInfo)) {
          this.$refs.relateNeckRingInfo.init(null, {status: 1}, cb)
        }
      })
    },
    openSprayHeadInfoDialog(cb) {
      this.sprayHeadInfoVisible = true
      this.$nextTick(() => {
        if (!this.R.isNil(this.$refs.relateSprayHeadInfo)) {
          this.$refs.relateSprayHeadInfo.init(null, {status: 1}, cb)
        }
      })
    },

    openClientInfoDialog(cb) {
      this.clientInfoVisible = true
      this.$nextTick(() => {
        if (!this.R.isNil(this.$refs.clientInfo)) {
          this.$refs.clientInfo.init(null, {status: 1}, cb)
        }
      })
    },


    openDeepCategoryInfoDialog(cb) {
      this.deepCategoryInfoVisible = true
      this.$nextTick(() => {
        if (!this.R.isNil(this.$refs.deepCategory)) {
          this.$refs.deepCategory.init(null, {status: 1}, cb)
        }
      })
    },
    openOrderIssuesNumberDialog(order) {
      this.orderIssuesNumberVisible = true
      this.modifyOrder = order
      const {orderIssuesNumber} = order

      this.orderIssuesNumber = orderIssuesNumber
    },
    openOrderModelDialog() {
      this.orderModelVisible = true
      this.$nextTick(() => {
        if (!this.R.isNil(this.$refs.orderModelInfo)) {
          this.$refs.orderModelInfo.init(null)
        }
      })
    },
    exportPlantFunc(rows) {
      this.onlineTime = ''
      this.orderPlanNoticeVisible = true
      this.deviceId = rows[0].deviceId
      this.initProductDeviceListByParent()
      this.initOrderDetailList()
      this.initProductInfoList()
      this.initDeepCategoryList()
      this.initModelInfoList()
      this.initSysUserInfoList()
      this.initProduceDeviceWorkbenchList(this.deviceId)
      this.tableListData = rows

    },

    initSysUserInfoList() {
      mRequest('systemApi/listAllUser', {}, (res) => {
        this.sysUserList = this.R.pathOr([], ['data', 'list'], res)
      })
    },

    initProductDeviceListByParent() {
      mRequest('productApi/getProductDeviceListByParent', {}, (res) => {
        this.productDeviceList = this.R.pathOr([], ['data', 'list'], res)
      })
    },
    initOrderDetailList() {
      mRequest('orderApi/getOrderDetailList', {}, (res) => {
        this.orderDetailList = this.R.pathOr([], ['data', 'list'], res)
      })
    },
    initProductInfoList() {
      mRequest('productApi/getProductInfoList', {}, (res) => {
        this.productInfoList = this.R.pathOr([], ['data', 'list'], res)
      })
    },
    initDeepCategoryList(attrName = '') {
      mRequest('deepApi/deepCategoryList', {}, (res) => {
        this.deepCategoryList = this.R.pathOr([], ['data', 'list'], res)
      })
    },
    initModelInfoList(attrName = 'modelInfoId') {
      mRequest('modelApi/getModelInfoList', {}, (res) => {
        this.modelInfoList = this.R.pathOr([], ['data', 'list'], res)
      })
    },
    initModelShelfList(attrName = 'modelShelfId') {
      mRequest('modelApi/getModelShelfList', {}, (res) => {
        this.modelShelfList = this.R.pathOr([], ['data', 'list'], res)
      })
    },
    initProduceDeviceWorkbenchList(deviceId) {
      mRequest('productApi/getDeviceChildrenListByParentId', {'parentId': deviceId}, (res) => {
        this.productDeviceWorkbenchList = this.R.pathOr([], ['data', 'list'], res)
      })
    },
    changeProductDeviceId(value) {
      if (value) {
        this.deviceWorkbenchList = []
        this.initProduceDeviceWorkbenchList(value)
      }
    },
    exportOrderNotFinish() {
      exportHandle('productApi/getProductOrderNotFinishExport', {})

    },

    updatePlanOrderStatus() {

      const ids = this.tableListData.map(item => {
        return item[this.primaryKey]
      })

      mRequest('orderApi/updatePlanOrderStatus', {
        'onlineTime': this.onlineTime,
        'deviceId': this.deviceId,
        'tableListData': this.tableListData
      }, (res => {
        let data = res.data
        if (data && data.code == 0) {

          this.$confirm('是否直接导出改计划?', '提示', {
            confirmButtonText: '导出',
            cancelButtonText: '取消',
            type: 'warning'
          }).then(() => {
            exportHandle('productApi/getProductPlanNoticeExport', {orderDetailIdList: ids})
          }).catch(() => {
          })

          this.$message({
            message: '操作成功',
            type: 'success',
            duration: 1500,
            onClose: () => {
              this.orderPlanNoticeVisible = false
              this.getDataList()
              this.$emit('refreshDataList')
            }
          })
        } else {
          this.$message.error(data.msg)
        }
      }))
    }
  },
  components: {
    ProductplannoticeAddOrUpdate,
    ProductinfoAddOrUpdate,
    ModelInfoAddOrUpdate,
    OrderModelAddOrUpdate,
    ClientInfoAddOrUpdate,
    DeepCategoryAddOrUpdate,
    CommodityInfoAddOrUpdateOrder,
    BottleCapInfoAddOrUpdate,
    CenterCoverInfoAddOrUpdate,
    NeckRingInfoAddOrUpdate,
    SprayHeadInfoAddOrUpdate,
    AddOrUpdate,
    treeView,
    tableView
  }
}
</script>
